﻿#pragma once

#include "geom_base.h"

namespace CAGD
{

/**
 * 几何点.
 */
template <int Dim> class GeomPointDim : public GeomBase
{
  public:
    /**
     * @brief 点构造.
     * @param point
     * @see
     */
    GeomPointDim(const BPntN<Dim> &point) : m_point(new BPntN<Dim>(point)), m_ref(false)
    {
    }

    /**
     * @brief 点构造.
     * @param point
     * @see
     */
    GeomPointDim(BPntN<Dim> *point) : m_point(point), m_ref(true)
    {
    }

    /**
     * @brief 销毁一般点.
     * @see
     */
    ~GeomPointDim()
    {
        if (!m_ref)
            delete m_point;
    }

    /**
     * @brief 常量引用.
     * @return
     * @see
     */
    const BPntN<Dim> &Point() const
    {
        return *m_point;
    }

    /**
     * @brief 修改点.
     * @param p
     * @see
     */
    void SetPoint(const BPntN<Dim> &p)
    {
        *m_point = p;
    }

    /**
     * @brief 返回类型.
     * @return
     * @see
     */
    GeomType Type() const override
    {
        return m_ref ? GeomType::POINTREF : GeomType::POINT;
    }

  protected:
    bool m_ref;
    BPntN<Dim> *m_point;
};

using GeomPoint = GeomPointDim<3>;
using Geom2dPoint = GeomPointDim<2>;

} // namespace CAGD
